<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    const obj = {
      name: "why",
      friend: {
        name: 'kobe',
        // running: function () {
        //   console.log("running~")
        // }
      }
    }

    // 1.直接调用
    // obj.friend.running()

    // 2.判断是否存在
    if(obj.friend && obj.friend.running){
      obj.friend.running()
    }

    // 3.可选链 ?.
    obj?.friend?.running?.()


  </script>
</body>

</html>